<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文章内容</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../../plugins/element-ui/index.css"/>
    <link rel="stylesheet" href="../../styles/common.css"/>
    <link rel="stylesheet" href="../../styles/page.css"/>
    <link rel="stylesheet" type="text/css" href="./editormd/css/editormd.min.css">
</head>
<body>
<div id="app">
<!--    返回按钮-->
    <el-button type="primary" @click="goBack">返回</el-button>
<!--    提交按钮-->
    <el-button type="primary" @click="submitForm">提交</el-button>
<div id="md-content" style="z-index: 1 !important;">
    <textarea>{{content}}</textarea>
</div>
</div>
<!-- 开发环境版本，包含了有帮助的命令行警告 -->
<script src="../../plugins/vue/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
<script src="./editormd/editormd.min.js"></script>
<!-- 引入组件库 -->
<script src="../../plugins/element-ui/index.js"></script>
<!-- 引入axios -->
<script src="../../plugins/axios/axios.min.js"></script>
<script src="../../js/request.js"></script>
<script src="../../api/article.js"></script>
<script src="../../js/validate.js"></script>
<script src="../../js/index.js"></script>
<script type="text/javascript">
    //初始化Markdown编辑器
    var contentEditor;
    $(function() {
        contentEditor = editormd("md-content", {
            width   : "100%",//宽度
            height  : "90%",//高度
            syncScrolling : "single",//单滚动条
            path    : "./editormd/lib/"//依赖的包路径
        });
    });
</script>

<script>
    new Vue({
        el: '#app',
        data() {
            return {
                id: '',
                content: ''

            }
        },

        created() {
            this.id = requestUrlParam('id')
            this.init()
        },
        mounted() {
        },
        methods: {
            async init() {
                //获取文章内容
                findArticleContentById(this.id).then(res => {
                    console.log(res)
                    this.content = res.data.content
                    contentEditor.setMarkdown(this.content)
                })



            },
            submitForm() {
                this.content = contentEditor.getMarkdown()
                updateArticleContent({aid:this.id,content:this.content}).then(res => {
                    console.log(res)
                    if (res.code == 1) {
                        this.$message({
                            message: '修改成功',
                            type: 'success',

                        })
                        //1秒后跳转
                        setTimeout(() => {
                            window.history.go(-1)
                        }, 1000)

                    } else {
                        this.$message({
                            message: '修改失败',
                            type: 'error'
                        })
                    }
                })
            },

            goBack() {
                window.history.go(-1)
            }
        }
    })
</script>
</body>
</html>